#include <bits/stdc++.h>

using namespace std;
const int maxn=50;
struct node
{
    int data;
    node* lchild;
    node* rchild;
};
int pre[maxn],in[maxn],post[maxn],n1;
node* createTreeByPostIN(int postL,int postR,int inL,int inR)
{
    if (postL>postR)
    {
        return nullptr;
    }
    node* root=new node;
    root->data=post[postR];
    int k;
    for (k=inL;k<=inR ;++k )
    {
        if (in[k]==post[postR])
        {
            break;
        }
    }
    int numLeft=k-inL;
    root->lchild=createTreeByPostIN(postL,postL+numLeft-1,inL,k-1);
    root->rchild=createTreeByPostIN(postL+numLeft,postR-1,k+1,inR);
    return root;
}
int num=0;
void BFS(node* root)
{
    queue<node*> q;
    q.push(root);
    while (!q.empty())
    {
        node* now=q.front();
        q.pop();
        printf("%d",now->data);
        ++num;
        if (num<n1)
        {
            printf(" ");
        }
        if (now->lchild!=nullptr)
        {
            q.push(now->lchild);
        }
        if (now->rchild!=nullptr)
        {
            q.push(now->rchild);
        }
    }
}
int main_1020()
{
    scanf("%d",&n1);
    for (int i=0;i<n1 ;++i )
    {
        scanf("%d",&post[i]);
    }
    for (int i=0;i<n1 ;++i )
    {
        scanf("%d",&in[i]);
    }
    node* root=createTreeByPostIN(0,n1-1,0,n1-1);
    BFS(root);
    return 0;
}
